import java.util.Arrays;


 class shujujiegou {
    public int[] arr=new int[10];
    public int usedSize;         //计数器
    private boolean isFull(){
        if(this.arr.length==this.usedSize){
            return true;
        }
        return false;
    }
    
    public void  MyArr(int pos,int data){                               //插入数组          
        if(isFull()){
            this.arr= Arrays.copyOf(this.arr, 2*this.arr.length);
         }
        if(pos<=usedSize&pos>=0){
            for(int i=usedSize-1;i>=pos;i--){
                arr[i+1]=arr[i];
            }
            this.arr[pos]=data;
            this.usedSize++;
        }
        else{
            return;
        }
    
}
public void add(){                                   //打印数组
   
        for(int i=0;i<this.usedSize;i++){
            System.out.println(this.arr[i]);
        }
 
}
public boolean contains(int toFind) {                      //查看是否有该值
    for(int i=0;i<arr.length;i++){
        if(arr[i]==toFind){
            return true;
        }
    }
    return false;
} 
public int search(int toFind){                          //返回该值下标
    for(int i=0;i<arr.length;i++){
        if(arr[i]==toFind){
            return i;
        }
    }
    return -1;
}
public int getPos(int pos){                                   //返回要查看的值
    if(isFull()){
        return -1;
    }
    if(pos<=usedSize&pos>=0){
        return this.arr[pos];
    }
    return -1;
}
public int size(){
    return usedSize;
}
private void checkPos(int pos){                                  //判断合法性
    if(pos<0||pos>=usedSize){
        throw new RuntimeException("pos位置不合法");
    }
}
public void remove(int toRemove){                            //删除
    if(search(toRemove)!=-1){
        for(int i=search(toRemove);i<this.usedSize-1;i++){
            arr[i]=arr[i+1];
        }
        usedSize--;
        return;
    }
    System.out.println("没有需要删除的数字");
}
public void clear(){                                                       //删除
    this.usedSize=0;
}
}


public class TestDemo{
    public static void main(String[]asgs){
        shujujiegou shujujiegou=new shujujiegou();
        for(int i=0;i<10;i++){
            shujujiegou.MyArr(i, i);
        }
        shujujiegou.add();
        shujujiegou.MyArr(10, 112);
        shujujiegou.add();
       /*  boolean a= shujujiegou.contains(6);
        System.out.println(a);
        int lin=shujujiegou.search(6);
        System.out.println(lin); */
        /* int shi=shujujiegou.getPos(6);
        System.out.println(shi);
        int a=shujujiegou.size();
        System.out.println(a); */
        shujujiegou.remove(1);
        shujujiegou.add();
    }
}

